我發現昨天匯出.fnt檔時少了一個步驟,
就是在ctrl+s之前,先用滑鼠點擊數字0~9以及:
然後才按下存檔,
如果沒點選的話,就不會匯出.png的檔案了
接續著昨天的動作後,
回到[Day-3] https://ithelp.ithome.com.tw/articles/10320834 新建的專案
一想到從那時到現在已經過了17天,就覺得時間過得真快...
總之,開啟當時新建的專案MyFirstWatch,
在resource目錄裡在新增一個目錄fonts,
接著把昨天另存好的.fnt檔、png檔也拉進來(我另存的檔名是jokerman)
在fonts目錄裡面新增一個fonts.xml檔案,像這樣
打開fonts.xml,貼上以下段落並儲存
<fonts>
<font id="myfonts" filename="jokerman.fnt" filter="0123456789:"/>
</fonts>
接著打開MyFirstWatchView.mc檔,參考昨天medium的文章,把程式碼調整如下:
import Toybox.Graphics;
import Toybox.Lang;
import Toybox.System;
import Toybox.WatchUi;
class MyFirstWatchFaceView extends WatchUi.WatchFace {
var myfonts = null;
function initialize() {
WatchFace.initialize();
}
// Load your resources here
function onLayout(dc as Dc) as Void {
myfonts=WatchUi.loadResource(Rez.Fonts.myfonts);
}
function onShow() as Void {
}
// Update the view
function onUpdate(dc as Dc) as Void {
dc.setColor(Graphics.COLOR_BLACK,Graphics.COLOR_BLACK);
dc.clear();
// Get and show the current time
var clockTime = System.getClockTime();
dc.setColor(Graphics.COLOR_RED,Graphics.COLOR_BLACK);
dc.drawText(dc.getWidth()/2, 30, myfonts, Lang.format("$1$",[clockTime.hour]), Graphics.TEXT_JUSTIFY_RIGHT);
dc.setColor(Graphics.COLOR_BLUE,Graphics.COLOR_BLACK);
dc.drawText(dc.getWidth()/2, 30, myfonts, Lang.format("$1$",[clockTime.min.format("%02d")]), Graphics.TEXT_JUSTIFY_LEFT);
}
function onHide() as Void {
}
function onExitSleep() as Void {
}
function onEnterSleep() as Void {
}
}
然後試跑看看!
結果不盡理想,明天再來看看有什麼要調整